package Impl;

import java.io.FileWriter;
import java.io.IOException;

import org.omg.CORBA.ORB;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
import org.omg.PortableServer.POAPackage.ServantNotActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;

public class Server {
	public static void main(String args[]) {
		
		ORB orb = ORB.init(args, null);
		POA rootpoa = null;
		try {
			rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
		} catch (InvalidName e3) {
			// TODO Auto-generated catch block
			e3.printStackTrace();
		}
		try {
			rootpoa.the_POAManager().activate();
		} catch (AdapterInactive e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		JobFactoryImpl obj = new JobFactoryImpl(rootpoa);
		
		org.omg.CORBA.Object ref = null;
		try {
			ref = rootpoa.servant_to_reference(obj);
		} catch (ServantNotActive | WrongPolicy e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		
		String IORenString = orb.object_to_string(ref);
		FileWriter fw = null;
		try {
			fw = new FileWriter("FicPourIOR");
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		try {
			fw.write(IORenString);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			fw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("server ready...");
		orb.run();
	}
}
